package edu.suda.cxtz.modules.security;

import edu.suda.cxtz.modules.security.bean.SecurityProperties;
import edu.suda.cxtz.modules.security.service.OnlineUserService;
import edu.suda.cxtz.modules.security.service.UserCacheManager;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;

@Configuration
@RequiredArgsConstructor
public class TokenConfigurer {

    private final TokenProvider tokenProvider;
    private final SecurityProperties properties;
    private final OnlineUserService onlineUserService;
    private final UserCacheManager userCacheManager;

    public void apply(HttpSecurity http) throws Exception{
        TokenFilter customFilter = new TokenFilter(tokenProvider, properties, onlineUserService, userCacheManager);
        http.addFilterBefore(customFilter, UsernamePasswordAuthenticationFilter.class);
    }
}
